package sm.upgrade.main;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import sm.upgrade.DataUpgradeImpl;
import sm.upgrade.util.UpgradeContext;

public class CheckDataConflictMain {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		UpgradeContext context = UpgradeContext.getInstance();
		ApplicationContext customerContext = null;
		ApplicationContext upgradeContext = null;
		ApplicationContext baseContext = null;

		int argsLength = args.length;
		String fileName = null;
		if (argsLength >= 2) {
			String customerContextFile = args[0].trim();
			customerContext = new ClassPathXmlApplicationContext(
					customerContextFile);
			String upgradeContextFile = args[1].trim();
			upgradeContext = new ClassPathXmlApplicationContext(
					upgradeContextFile);
			if (argsLength == 3) {
				String baseContextFile = args[2].trim();
				if (baseContextFile.indexOf(".") != -1) {
					baseContext = new ClassPathXmlApplicationContext(
							baseContextFile);
				} else {
					fileName = baseContextFile;
				}
			} else if (argsLength == 4) {
				String baseContextFile = args[2].trim();
				baseContext = new ClassPathXmlApplicationContext(
						baseContextFile);
				fileName = args[3].trim();
			}
		} else {
			customerContext = context.getOrCreateCustomerContext();
			upgradeContext = context.getOrCreateUpgradeContext();
			baseContext = context.getOrCreateBaseContext();
		}

		DataUpgradeImpl dataUpgrade = new DataUpgradeImpl(customerContext,
				upgradeContext, baseContext);

		if (fileName != null) {
			dataUpgrade.show3wayConflict(fileName);
		} else {
			dataUpgrade.show3wayConflict();
		}
	}
}
